<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Test_model extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function check_tester($id_te,$testtitle)
    {
        $this->db->select('*');
        $this->db->from('tester');
        $this->db->where('id_te',$id_te);
        $this->db->where('testtitle',$testtitle);
        $query=$this->db->get();
        return $query;
    }
    public function select_testtitle($testtitle)
    {
        $this->db->distinct();
        $this->db->select('test_title');
        $this->db->from('tester');
        $this->db->where('testtitle',$testtitle);
        $query=$this->db->get();
        return $query;
    }
    public function select_tester()
    {
        $this->db->select('*');
        $this->db->from('tester');
        $query=$this->db->get();
        return $query;
    }
    public function type_table_ques($id_question)
    {
        $this->db->select('*');
        $this->db->from('compare');
        $this->db->where('id_question',$id_question);
        $this->db->like('q','f1_q');
        $query=$this->db->get();
        return $query;
    }
    public function type_table_ques1($id_question)
    {
        $this->db->select('*');
        $this->db->from('compare');
        $this->db->where('id_question',$id_question);
        $this->db->like('q','f2_q');
        $query=$this->db->get();
        return $query;
    }
    public function get_content_ques($q,$id_question)
    {
        $this->db->select('*');
        $this->db->from($q);
        $this->db->where('id_question',$id_question);
        $query=$this->db->get();
        return $query;
    }
    public function insert_answer_ques1($id_te,$id_question,$sub_ans)
    {
        $data = array(  
            'id_te'=>$id_te,                  
            'id_question'=>$id_question,
            'sub_an'=>$sub_ans
                    );
        $this->db->insert('qsubmit',$data);
    }
    public function check_submit($id_question,$id_te)
    {
        $this->db->select('*');
        $this->db->from('qsubmit');
        $this->db->where('id_question',$id_question);
        $this->db->where('id_te',$id_te);
        $query=$this->db->get();
        return $query;
    }
    public function update_submit($id_qsub,$sub_an)
    {
        $update_submit=array(
            'sub_an'=>$sub_an

        );
        $updatesubmit=$this->db->update('qsubmit',$update_submit,array('id_qsub'=>$id_qsub));
        return $updatesubmit;

    }
    public function find_max_ques()
    {
        $this->db->select('*');
        $this->db->from('compare');
        $query=$this->db->get();
        return $query;
    }
    public function find_max_ques_f2()
    {
        $text='f2_q';
        $sql="SELECT q FROM compare WHERE q LIKE '".$text."%'";
        $query=$this->db->query($sql);
        return $query;
    }
    public function find_max_ques_f1()
    {
        $text='f1_q';
        $sql="SELECT q FROM compare WHERE q LIKE '".$text."%'";
        $query=$this->db->query($sql);
        return $query;
    }
    public function update_tester($id_te,$password,$name,$testtitle,$id_mg,$test_title,$id_mk)
    {
        $update_submit=array(
            'password'=>md5($password),
            'name'=>$name,
            'testtitle'=>$testtitle,
            'id_mg'=>$id_mg,
            'test_title'=>$test_title,
            'id_mk'=>$id_mk

        );
        $updatesubmit=$this->db->update('tester',$update_submit,array('id_te'=>$id_te));
        return $updatesubmit;
    }
    public function insert_tester($id_te,$password,$name,$testtitle,$id_mg,$test_title,$id_mk)
    {
        $data = array(  
            'id_te'=>$id_te,                  
            'password'=>md5($password),
            'name'=>$name,
            'testtitle'=>$testtitle,
            'id_mg'=>$id_mg,
            'test_title'=>$test_title,
            'id_mk'=>$id_mk
                    );
        $this->db->insert('tester',$data);
    }
}
?>
